@extends('admin.layouts.main_slight')

@section('content')

<style>
    body{padding: 10px;}
</style>
<?php
$get = $get ?? [];
use App\Extend\Admin\Common\Html\EasyForm;
use App\Http\Admin\Models\Fields\System\Menu;

$easyForm = new EasyForm($get, Menu::class);
?>
<body>

<!-- 内容主体区域 -->
<div style="padding: 15px;">
	<?php



    $url = empty($get['id']) ? './add' : './update';
	?>
	<form class="layui-form layui-form-pane1" method="post" action="<?php echo $url; ?>" lay-filter="first">
	@csrf
		<?php
        echo $easyForm->hidden('id');
		echo $easyForm->text('pid');

		$data = [
			'_self' => '_self',
			'_blank'=> '_blank',
			'_parent' => '_parent',
			'_top'	=> '_top',
		];
		echo $easyForm->select('target', $data);
		echo $easyForm->text('name');
		echo $easyForm->text( 'url');
		echo $easyForm->text( 'sort');
		echo $easyForm->select('icon', $icon);
		?>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="*">提交</button>
				<button onclick="closeIframe();" type="button" class="layui-btn">取消</button>
			</div>
		</div>
	</form>

	<br><br><br>

	<script>

		layui.use('form', function(){
			const $ = layui.$;
			const form = layui.form;

			//自定义验证规则
			form.verify({
				//验证是否关联设备
				checkboxMustBe: function (value) {
					return ;
					let isSelect = 0;
					$('.equipment_body').find('input').each(function(index,ele){
						if($(ele).is(':checked')){
							isSelect = 1;
							return false;
						}
					});
					if(!isSelect) return '请选择关联设备';
				}
			});

			//监听提交
			form.on('submit(*)', function(data){
				$.post('<?php echo $url ?>' , data.field , function(d) {
					console.log(d.code);
					if(d.code != 0) {
						//返回失败
						layer.msg(d.msg);
						return false;
					}
					layer.msg('成功');
					setTimeout(function() {
						const index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭
						parent.layui.table.reload('list');
					},1000);
				});
				return false;
			});

		});

	</script>
</div>

</body>

@endsection
